package com.gt.quality.system.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gt.quality.config.handler.EasyBaseMapper;
import com.gt.quality.system.entity.SysUser;
import com.gt.quality.system.entity.dto.SysUserDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 用户信息表(SysUser)表数据库访问层
 *
 * @author makejava
 * @since 2026-11-25 16:30:08
 */
@Mapper
@SuppressWarnings("all")
public interface SysUserMapper extends EasyBaseMapper<SysUser> {

    /**
     * Description: 用户分页查询
     *
     * @author: makeJava
     * @date: 2026-12-22 20:01:50
     * @return: List
     */
    @Select(value = """
             <script>
             select su.user_id,su.dept_id,su.user_name,
             su.nick_name,su.user_type,su.email,su.phone_number,CASE su.sex WHEN '1' THEN '女'  WHEN '0' THEN '男' ELSE '未知' END AS sex,sai.avatar_address as avatar,su.status,su.login_ip,su.login_date,su.create_time,su.update_time,su.remark,sd.dept_name
             from sys_user su 
             left join sys_avatar_info sai on su.user_id = sai.user_id
             left join sys_dept sd on sd.dept_id = su.dept_id
             where su.del_flag = 0 
             <if test="bean.userName != null and bean.userName != ''">
               and su.user_name like concat('%',#{bean.userName},'%')
             </if>
             <if test="bean.nickName != null and bean.nickName != ''">
               and su.nick_name like concat('%',#{bean.nickName},'%')
             </if>
              <if test="bean.sex != null and bean.sex != ''">
               and su.sex = #{bean.sex}
             </if>
               <if test="bean.deptId != null ">
               and su.dept_id = #{bean.deptId}
             </if>
             order by su.create_time desc 
             </script>
            """)
    List<SysUserDTO> listQueryForWhereParam(@Param("page") IPage<SysUserDTO> page, @Param("bean") SysUser sysUser);
}

